var app = getApp();
const Utils = require('../../utils/util.js')

const pathUrl = app.globalData.pathUrl;
Page({
  data: {
    pageHidden: true,
    pathUrl: pathUrl,
    orderStatusType: 0,
    fxjOut03: '',
    list: [],
    pageNumber: 0,
    loading: false, //"上拉加载"的变量，默认false，隐藏  
    loadingComplete: false,  //“没有数据”的变量，默认false，隐藏  
  },
  onLoad: function (options) {
    var openId = wx.getStorageSync('openId');
    this.setData({
      openId: openId
    });
    wx.setNavigationBarTitle({
      title: options.name,
    });

  },
  clickTab: function (e) {
    var that = this;
    if (this.data.orderStatusType === e.currentTarget.dataset.index) {
      return false;
    } else {
      wx.showLoading({
        title: '加载中',
      })
      that.setData({
        orderStatusType: e.currentTarget.dataset.index,
        loadingComplete: false, //把“没有数据”设为true，显示  
        loading: false,//把"上拉加载"的变量设为false，隐藏  
        pageNumber: 0,
        list: []
      })
      this.onReachBottom();
    }

  },
  // 查看详情
  viewDetail: function () {

  },
  // 处理
  dealWith: function () {

  },




  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
    that.setData({
      pageHidden: true,
      orderStatusType: 0,
      loadingComplete: false, //把“没有数据”设为true，显示  
      loading: false,//把"上拉加载"的变量设为false，隐藏  
      pageNumber: 0,
      list: []
    })
    this.onReachBottom();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
    that.setData({
      loadingComplete: false, //把“没有数据”设为true，显示  
      loading: false,//把"上拉加载"的变量设为false，隐藏  
      pageNumber: 0,
      orderStatusType: that.data.orderStatusType,
      list: []
    });
    this.onReachBottom();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var pageNumber = that.data.pageNumber + 1;
    var allList = that.data.list;
    wx.request({
      // /rest/fxjNoticeController/list/wwq?pageNumber=1&pageSize=10&ntStatus=1&ntType=&orderNo=&ntName=&dateRange=null&startDate=&endDate=
      url: pathUrl + '/rest/fxjOrderMainController/list/admin',
      data: {
        pageNumber: pageNumber,
        pageSize: 10
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.ok) {
          wx.hideLoading();
          that.setData({
            pageHidden: false
          });
          var arr = [];
          if (res.data.data.length > 0) {

            allList = allList.concat(res.data.data);
            if (res.data.data.length < 10) {
              that.setData({
                pageNumber: pageNumber,
                list: allList,
                loadingComplete: true, //把“没有数据”设为true，显示  
                loading: false //把"上拉加载"的变量设为false，隐藏  
              });
            } else {
              that.setData({
                pageNumber: pageNumber,
                list: allList,
                loading: false
              });
            }
          } else {
            that.setData({
              loadingComplete: true, //把“没有数据”设为true，显示  
              loading: false //把"上拉加载"的变量设为false，隐藏  
            });
          }
        } else {
          wx.hideLoading();
          that.setData({
            pageHidden: true
          });
          wx.showModal({
            title: '提示',
            content: '获取数据失败',
            confirmColor: '#7aa6d1',
            showCancel: false
          });
        }
      }
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
});